<template>
  <div class="content content55">
    <div>检测条件：温度T：<el-input v-model="form.temperature" class="input-line" />℃；气压p：<el-input v-model="form.pressure" class="input-line" />Kpa</div>
    <div class="innertitle">
      1.等中心偏差：
    </div>
    <div>
      不带落地支架X-刀的等中心偏差：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>线束能量</td>
        <td><el-input v-model="form.isocenterDeviation.energy" class="input-line" /></td>
        <td>旋转角度0</td>
        <td>照射剂量，cGy</td>
        <td>测量结果，mm</td>
      </tr>
      <tr>
        <td colspan="2">大机架旋转不同黑线中心最大距离（<i>$d_a$</i>）</td>
        <td rowspan="3">0°、45°、<br/>90°、135°</td>
        <td rowspan="3"><el-input v-model="form.isocenterDeviation.exposureDose" class="input-line" /></td>
        <td><el-input v-model="form.isocenterDeviation.result_1" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">小机头旋转不同黑线中心最大距离（<i>$d_b$</i>）</td>
        <td><el-input v-model="form.isocenterDeviation.result_2" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">治疗床旋转不同黑线中心最大距离（<i>$d_c$</i>）</td>
        <td><el-input v-model="form.isocenterDeviation.result_3" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">等中心偏差（<i>$d_1$</i>），mm</td>
        <td colspan="3"><el-input v-model="form.isocenterDeviation.isocenterDeviation" class="input-line" /></td>
      </tr>
    </table>
    <div>
      带落地支架X-刀的等中心偏差： 线束能量：<el-input v-model="form.isocenterDeviation.wireHarnessEnergy" class="input-line" />，计划照射剂量：<el-input v-model="form.isocenterDeviation.planExposureDose" class="input-line" />cGy，准直器尺寸 ：<el-input v-model="form.isocenterDeviation.collimatorSize" class="input-line" />mm
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>机架旋转角度</td>
        <td v-for="(tdItem,tdIndex) in isocenterDeviation.table" :key="tdIndex">{{tdItem.ang}}°</td>
      </tr>
      <tr>
        <td>治疗床旋转角度</td>
        <td v-for="(tdItem,tdIndex) in isocenterDeviation.table" :key="tdIndex">{{tdItem.angz}}°</td>
      </tr>
      <tr>
        <td>几何中心的距离，mm</td>
        <td v-for="(tdItem,tdIndex) in isocenterDeviation.table" :key="tdIndex"><el-input v-model="form.isocenterDeviation['centerDistance_'+(tdIndex+1)]" class="input-line" /></td>
      </tr>
      <tr>
        <td>最大偏差，mm</td>
        <td :colspan="isocenterDeviation.table.length"><el-input v-model="form.isocenterDeviation.maxDeviation" class="input-line" /></td>
      </tr>
    </table>
    <div class="latex">
      <i>$d_1 = \sqrt {(d_a/2)^2 + (d_b/2)^2 + (d_c/2)^2}$</i>
    </div>
    <div class="innertitle">
      2.治疗定位偏差：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>线束能量</td>
        <td><el-input v-model="form.treatmentPositioningDeviation.wireHarnessEnergy" class="input-line" /></td>
        <td>准直器直径</td>
        <td>照射剂量，cGy</td>
        <td>测量结果，mm</td>
      </tr>
      <tr v-for="(trItem,trIndex) in treatmentPositioningDeviation.table.tr" :key="trIndex">
        <td colspan="2" v-html="trItem+'轴照射野中心与靶点中心距离（<i>$d_{'+trItem+'})$</i>'"></td>
        <td v-if="trIndex == 0" :rowspan="treatmentPositioningDeviation.table.tr.length"><el-input v-model="form.treatmentPositioningDeviation.collimatorDiameter" class="input-line" /></td>
        <td v-if="trIndex == 0" :rowspan="treatmentPositioningDeviation.table.tr.length"><el-input v-model="form.treatmentPositioningDeviation.exposureDose" class="input-line" /></td>
        <td><el-input v-model="form.treatmentPositioningDeviation['result_'+(trIndex+1)]" class="input-line" /></td>
      </tr>
      <tr>
        <td colspan="2">等中心偏差（<i>$d_2$</i>），mm</td>
        <td colspan="3"><el-input v-model="form.treatmentPositioningDeviation.isocenterDeviation" class="input-line" /></td>
      </tr>
    </table>
    <div class="latex">
      <i>$d_2 = \sqrt {(d_{LAT})^2+(d_{AP})^2+(d_{VERT})^2}$</i>
    </div>
    <div class="innertitle" style="display: flex;justify-content: space-between;">
      3.照射野尺寸与标称值最大偏差：<span style="font-weight: normal;">线束能量：<el-input v-model="form.maxDeviation.wireHarnessEnergy" class="input-line" />计划照射剂量：<el-input v-model="form.maxDeviation.planExposureDose" class="input-line" />cGy</span>
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>FWHM预设档,mm</td>
        <td v-for="tbodyIndex in maxDeviation.table.tbody" :key="tbodyIndex" :colspan="maxDeviation.table.td.length"><el-input v-model="form.maxDeviation['defaultValue_'+tbodyIndex]" class="input-line" /></td>
      </tr>
      <tr>
        <td>方向</td>
        <template v-for="tbodyIndex in maxDeviation.table.tbody" >
          <td v-for="(tdItem,tdIndex) in maxDeviation.table.td" :key="'td'+tbodyIndex+tdIndex">{{tdItem}}</td>
        </template>
      </tr>
      <tr>
        <td>标称值,mm</td>
        <template v-for="tbodyIndex in maxDeviation.table.tbody" >
          <td v-for="(tdItem,tdIndex) in maxDeviation.table.td" :key="'td'+tbodyIndex+tdIndex">
            <el-input v-model="form.maxDeviation['standardValue_'+tbodyIndex+'_'+tdItem]" class="input-line" />
          </td>
        </template>
      </tr>
      <tr>
        <td>FWHM,mm</td>
        <template v-for="tbodyIndex in maxDeviation.table.tbody" >
          <td v-for="(tdItem,tdIndex) in maxDeviation.table.td" :key="'td'+tbodyIndex+tdIndex">
            <el-input v-model="form.maxDeviation['fwhm_'+tbodyIndex+'_'+tdItem]" class="input-line" />
          </td>
        </template>
      </tr>
      <tr>
        <td :colspan="1+maxDeviation.table.td.length">测量值与标称值最大偏差，mm</td>
        <td :colspan="(maxDeviation.table.tbody-1)*maxDeviation.table.td.length">
          <el-input v-model="form.maxDeviation.maxDeviation" class="input-line" />
        </td>
      </tr>
    </table>
    <div class="innertitle" style="display: flex;justify-content: space-between;">
      4.焦平面上照射半影宽度：<span style="font-weight: normal;">线束能量：<el-input v-model="form.penumbraWidth.wireHarnessEnergy" class="input-line" />计划照射剂量：<el-input v-model="form.penumbraWidth.planExposureDose" class="input-line" />cGy</span>
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>FWHM预设档,mm</td>
        <td v-for="tbodyIndex in penumbraWidth.table.tbody" :key="tbodyIndex" :colspan="penumbraWidth.table.td.length"><el-input v-model="form.penumbraWidth['defaultValue_'+tbodyIndex]" class="input-line" /></td>
      </tr>
      <tr>
        <td>方向</td>
        <template v-for="tbodyIndex in penumbraWidth.table.tbody" >
          <td v-for="(tdItem,tdIndex) in penumbraWidth.table.td" :key="'td'+tbodyIndex+tdIndex">{{tdItem}}</td>
        </template>
      </tr>
      <tr>
        <td>左侧半影，mm</td>
        <template v-for="tbodyIndex in penumbraWidth.table.tbody" >
          <td v-for="(tdItem,tdIndex) in penumbraWidth.table.td" :key="'td'+tbodyIndex+tdIndex">
            <el-input v-model="form.penumbraWidth['leftPenumbra_'+tbodyIndex+'_'+tdItem]" class="input-line" />
          </td>
        </template>
      </tr>
      <tr>
        <td>右侧半影，mm</td>
        <template v-for="tbodyIndex in penumbraWidth.table.tbody" >
          <td v-for="(tdItem,tdIndex) in penumbraWidth.table.td" :key="'td'+tbodyIndex+tdIndex">
            <el-input v-model="form.penumbraWidth['rightPenumbra_'+tbodyIndex+'_'+tdItem]" class="input-line" />
          </td>
        </template>
      </tr>
      <tr>
        <td>最大半影宽度，mm</td>
        <td :colspan="(penumbraWidth.table.tbody)*penumbraWidth.table.td.length">
          <el-input v-model="form.penumbraWidth.penumbraWidth" class="input-line" />
        </td>
      </tr>
    </table>
    <div class="innertitle">
      5.等中心处计划剂量与实测剂量相对偏差：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>线束能量</td>
        <td>等中心处计划照射剂量<i>$D_t$</i>，cGy</td>
        <td>准直器直径，mm</td>
        <td>测量值<i>$M_u$</i>，Gy</td>
        <td>校准因子<br/><i>$N_x$</i></td>
        <td>校准值<i>$D_γ$</i><br/>Gy</td>
        <td>水中吸收剂量<i>$D_w$</i>，Gy</td>
        <td>相对偏差<i>$\Delta$</i><br/>%</td>
      </tr>
      <tr v-for="trIndex in relativeDeviation.table.tr" :key="trIndex">
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.wireHarnessEnergy" class="input-line" /></td>
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.planExposureDose" class="input-line" /></td>
        <td><el-input v-model="form.relativeDeviation['collimatorDiameter_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.relativeDeviation['measureValue_'+trIndex]" class="input-line" /></td>
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.calibrationFactor" class="input-line" /></td>
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.calibrationValue" class="input-line" /></td>
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.absorbedDose" class="input-line" /></td>
        <td v-if="trIndex == 1" :rowspan="relativeDeviation.table.tr"><el-input v-model="form.relativeDeviation.relativeDeviation" class="input-line" /></td>
      </tr>
    </table>
    <div class="latex">
      <i>$\Delta = \frac {D_w - D_t}{D_t} \times 100 \%$</i>
      ，&nbsp;&nbsp;<i>$D_w = D_r \cdot \frac {(\mu_{en} / \rho)_w}{(\mu_{en}/\rho)_m}$</i>
      ，&nbsp;&nbsp;<i>$\frac {(\mu_{en}/ \rho)_w}{(\mu_{en}/\rho)_{聚苯乙烯}} = 1.036$</i>
      ，&nbsp;&nbsp;<i>$D_r = \frac {M_u \times N_{D,air} \times S_{w,air} \times P_{wall} \times P_{cav} \times P_{cel}} {PDD_s}$</i>
      ，&nbsp;&nbsp;<i>$N_{D,air} = N_k(1-g)k_{att}k_mk_{cel}$</i>
      ，&nbsp;&nbsp;<i>$N_k = 2.58 \times 10^{-2} N_x \frac {w}{e} \frac{1}{1-g}$</i>
      ，&nbsp;&nbsp;<i>$P_{wall} = \frac {\alpha \times S_{wall,air} \times (\mu_{en}/ \rho)_{w,wall} + (1-\alpha) \times S_{W,air}}{S_{W,air}}$</i>
    </div>
  </div>
</template>

<script>
  import {getInfoById, postInfo} from '@/api/testItem/item55'
  export default{
    name:'testItem55',
    props: {
    	// tab栏
      activeNameEquipment: {
    		type: String,
        default: "0",
      },
    	// 基本信息数据
      basicForm: {
    		type: Object,
        default: () => {
    			return {}
    		},
      },
    },
    data(){
      return{
        initFlag:false,
        "sdd": {
          action:'saveInfo',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
        },
        "isocenterDeviation": {
          action:'isocenterDeviation',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:[
            {'ang':0,'angz':'0'},{'ang':90,'angz':'0'},{'ang':270,'angz':'0'},{'ang':120,'angz':'45'},{'ang':330,'angz':'270'}
          ]
        },
        "treatmentPositioningDeviation": {
          action:'deviation',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            tr:['LAT','AP','VERT']
          }
        },
        "maxDeviation": {
          action:'maxDeviation',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            tbody:6,
            td:['x','y']
          }
        },
        "penumbraWidth": {
          action:'penumbraWidth',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            tbody:6,
            td:['x','y']
          }
        },
        "relativeDeviation": {
          action:'relativeDeviation',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            tr:6
          }
        },
        "form": {
          "itemsId": 0,
          "resultId": 0,
          "temperature": 0.0,
          "pressure": 0.0,
          "isocenterDeviation": {
            "itemsId": 0
          },
          "treatmentPositioningDeviation": {
            "itemsId": 0
          },
          "maxDeviation": {
            "itemsId": 0
          },
          "penumbraWidth": {
            "itemsId": 0
          },
          "relativeDeviation": {
            "itemsId": 0
          }
        }
      }
    },
    watch:{
      activeNameEquipment: {
        handler(val) {
          this.$nextTick(()=>{
            let resultId = this.basicForm.resultId;
            getInfoById(resultId).then(response => {
              if(response.code == 200){
                let data = response.data;
                for(let keys in data){
                  this.setData(keys,data[keys]);
                }
                 setTimeout(()=>{
                   this.initFlag = true;
                 },300)
              }
            }).catch((response) => {
               this.$emit("loadingchange", true);
             });
             });
        },
        deep: true,
        immediate: true
      },
      "form.isocenterDeviation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'isocenterDeviation');
         }
        },
        deep:true,
      },
      "form.treatmentPositioningDeviation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'treatmentPositioningDeviation');
         }
        },
        deep:true,
      },
      "form.maxDeviation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'maxDeviation');
         }
        },
        deep:true,
      },
      "form.penumbraWidth":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'penumbraWidth');
         }
        },
        deep:true,
      },
      "form.relativeDeviation":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'relativeDeviation');
         }
        },
        deep:true,
      },
      "form.temperature":{
          handler(newName, oldName) {
            if(this.initFlag){
             this.validateData(this.form,'sdd');
            }
          },
        },
      "form.pressure":{
        handler(newName, oldName) {
          if(this.initFlag){
           this.validateData(this.form,'sdd');
          }
        },
      },
    },
    methods:{
      //修改数据
      setData(name,data){
        this.form[name] = data ? data : (this[name] ? {}:null);
      },
      //表单修改提交后端
       postForm(param,name){
         param['itemsId'] = this.form.itemsId;
         this.$emit("loadingchange", true);
      	 postInfo(param,this[name].action).then(res=>{
      		 this.$emit("loadingchange", false);
      		 if(res.code == 200){
      			 this[name].flag = false;
      			 if(name != 'sdd'){
      				this.setData(name,res.data);
      			 }
      		 }
      	 })
      },
      validateType(arr,keys,obj){
      	if(obj.like){
      		for(let i=0;i<arr.length;i++){
      			if(keys.indexOf(arr[i]) != -1){
      				return true;
      			}
      		}
      		return false;
      	}else{
      		if(arr.indexOf(keys) != -1){
      			return true;
      		}
      		return false;
      	}
      },
       //数据验证
       validateData(newName,myName){
      	 if(!this[myName].noClear){
      		clearTimeout(this[myName].loading);
      	 }else{
      		 this[myName].noClear = false;
      	 }
         let regNumber = /^[-]?\d*([.](\d+))?$/;//小数验证正则
         let regRepNumber = /[^-?\d.,]/g;//将除小数外的符号消除正则
         let regInt = /^\d*$/;//整数验证正则
         let regRepInt = /[^-?\d,]/g;//将除小数外的符号消除正则
         let reg,regRep;
         let repStr = '';
      	 let intResult
         if(JSON.stringify(newName) != '{}'){
           //遍历该对象所有字段进行验证
           for(let keys in newName){
             //数字验证环节
      			 if((typeof newName[keys] == 'string') ||  (typeof newName[keys] == 'number')){
      				if(newName[keys] && !this.validateType(this[myName].notNumber,keys,this[myName])){
      					intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      					reg = intResult ? regInt:regNumber;
      				  let bool = !reg.test(newName[keys]);
      				  if(bool){
      						setTimeout(()=>{
      							intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      							regRep = intResult ? regRepInt:regRepNumber;
      									repStr = newName[keys] + '';
      							repStr =  repStr.replace(regRep,'');
      							if(repStr != (newName[keys]+'')){
      								if(!this[myName].noClear){
      									this[myName].noClear = true;
      								}
      								newName[keys] = repStr;
      							}
      						},100);
      						if(this[myName].flag){
      						 this[myName].flag = false;//如果数字验证不通过不需要请求后端
      						}
      				  }
      				}
      			 }
           }
      		 this.isPost(newName,myName);
         }
       },
       isPost(newName,myName){
      	 if(this[myName].flag){//是否请求后端判断
      	  let postBody = {};
      	  for(let i in newName){
      	    if(newName[i] !== null && newName[i] !== undefined){
      	      postBody[i] = newName[i];
      	    }
      	  }
      	  if(JSON.stringify(postBody) != '{}'){
      			this[myName].loading = setTimeout(()=>{
      				this.postForm(postBody,myName);
      			},800)
      	  }
      	 }else{
      		 this[myName].flag = true;
      	 }
       },
    },
  }
</script>

<style lang="scss" scoped>
  @import '../content.scss';

  .miniFont {
    font-size: 10px;
  }

  .miniFontCenter {
    margin-top: 8px;
  }

  .content55 {
    padding-inline: 0 !important;
    ::v-deep .el-input__suffix{
      display: none;
    }
    .latex{
      margin-top: 15px;
    }
    table {
      width: 100%;

      td {
        max-width: 100px;

        ::v-deep .el-checkbox__label {
          white-space: break-spaces;
        }
      }

      .el-input {
        width: 100% !important;
      }

      .multipleInput {
        .el-input {
          width: 50px !important;
        }
      }
    }

    .innertitle {
      display: block;
      margin-left: 0;
    }

    .table1 {
      .el-radio {
        display: flex;
        align-items: center;
      }
    }

    #hearderTR td:nth-child(7) {
      display: none;
    }
  }
</style>
